import json
import re

import requests
from lxml import etree
import asyncio
import aiohttp
import threading

async def fetch(session, url):
    async with session.get(url) as response:
        response = await response.json()
        for item in response['data']:
            print(item)


async def main():
    async with aiohttp.ClientSession() as session:
        urls = [f'https://api.web.360kan.com/v1/rank?cat={t}'for t in range(1,7)]

        task = [fetch(session,url)for url in urls]
        await asyncio.gather(*task)
asyncio.run(main())

# def fetch(url):
#     response = requests.get(url)
#     print(response.json())
#     # for item in response.json():
#     #     print(item)
#
# def main():
#     urls = [f'https://api.web.360kan.com/v1/rank?cat={t}' for t in range(1, 5)]
#     threads = [threading.Thread(target=fetch, args=(u,)) for u in urls]
#     for t in threads:
#         t.start()
#     for t in threads:
#         t.join()
#
# if __name__ == '__main__':
#
#     main()




#
# url = 'https://api.web.360kan.com/v1/rank?cat=1'
# response = requests.get(url)
# print(response.text)
#
# items = response.json().get('data')
# for item in items:
#     print(item['title'])


# for item in rank_list:
#     print(item['title'])









